package cn.tedu.duotai;
/*
方法重载 - 编译时多态的体现
 */
public class Demo {
    public static void main(String[] args) {
        //先创建AddDemo对象
        AddDemo addDemo = new AddDemo();
        addDemo.sum(3,5);//编译期间就能根据实参来确定当前调用哪个重载方法
        addDemo.sum(new int[]{1,2,3});//匿名对象
        //addDemo.sum(1,2,3);//编译报错
    }
}
class AddDemo{
    public int sum(int a,int b){
        return a+b;
    }
    public double sum(double d1,double d2){
        return d1+d2;
    }
    public int sum(int[] arr){
        int sum =0;
        for (int i = 0; i <arr.length ; i++) {
            sum+=arr[i];
        }
        return sum;
    }
}
